package com.docMan.utils;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class FileIndexService {
	private ExecutorService executorService=Executors.newSingleThreadExecutor();
	private static FileIndexService fileIndexService=new FileIndexService();
	public static FileIndexService getInstance(){
		return fileIndexService;
	}
	
	public void index(Runnable indexRunnable){
		executorService.submit(indexRunnable);
	}
	
	public void updateIndex(Runnable updateRunnable ){
		executorService.submit(updateRunnable);
	}
	public void deleteIndex(Runnable deleteRunnable ){
		executorService.submit(deleteRunnable);
	}
	/**
	 * 在文件夹中创建和删除出文件夹或者文件时，要更新文件夹的文件数和文件夹数以及文件夹的大小
	 * 且这个更新要是线程并发安全的，所以放到单线程的线程池中去执行
	 * 确保对文件夹的更新操作同时执行数量为1
	 * @param updateDirectoryRunnable 
	 */
	public void updateDirectory(Runnable updateDirectoryRunnable){
		executorService.submit(updateDirectoryRunnable);
	}
	
	/**
	 * 线程安全的更新网盘的信息 
	 * @param upadteDiskRunnable
	 */
	public void updateDisk(Runnable upadteDiskRunnable){
		executorService.submit(upadteDiskRunnable);
	}
	public String getImgClass(String path){
		String type =path.substring(path.lastIndexOf(".")+1, path.length());
		switch (type) {
		case "doc":
			return "file_word_ico_d32";
		case "docx":
			return "file_word_ico_d32";
		case "xls":
			return "file_excel_ico_d32";
		case "jpg":
			return "file_photo_ico_d32";
		case "png":
			return "file_photo_ico_d32";
		case "pdf":
			return "file_pdf_ico_d32";
		case "txt":
			return "file_txt_ico_d32";
		default:
			return "file_chm_ico_d32";
		}
	}
}
